import java.util.PriorityQueue;
import java.util.Scanner;

public class P3253 {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		long cost = 0;
		int lChild,rChild;
		int size = in.nextInt();
		PriorityQueue<Integer> priorityQueue = new PriorityQueue<Integer>();
		for (int i = 0; i < size; i++) {
			priorityQueue.add(in.nextInt());
		}
		while (priorityQueue.size() > 1) {
			lChild=priorityQueue.poll();
			rChild=priorityQueue.poll();
			priorityQueue.add(lChild+rChild);
			cost+=lChild+rChild;
			
		}
		if(size==1){
			System.out.println(priorityQueue.poll());
		} else  if(size==0){
			System.out.println(0);
		}else{
			System.out.println(cost);
		}
	}

}
